package tw.com.msig.spring.hibernate.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tw.com.msig.spring.hibernate.dao.UserDao;
import tw.com.msig.spring.hibernate.entity.User;

@Service
public class UserService {

	@Autowired
	private UserDao userDao;
	
	public List<User> getAll() {
		return userDao.findAll();
	}
	
	public User insert(User user) {
		return userDao.insert(user);
	}
	
	public User getOne(Long id) {
		return userDao.findOne(id);
	}
	
	public void delete(Long id) {
		userDao.delete(id);
	}
	
	public void update(User user) {
		
		User dbUser = getOne(user.getId());
		dbUser.setName(user.getName());
		userDao.update(dbUser);
	}
	
	
	
	
	
	
	
	
}